<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2015/12/29
 * Time: 18:26
 */

class materialgpapi extends CI_Controller{
    function __construct()
    {
        parent::__construct();
        $this->load->model('Material_model');
    }
    public function index()
    {
        $gp=gp();
        foreach($gp['data'] as $key=>$val){
            switch($gp['type']){
                case 'update':
                    $this->Material_model->addProductWuliao($key, $val);
                    break;
                case 'add':
                    $this->Material_model->addProductWuliao($val);
                    break;
            }
        }
    }


    function getOrderMaterial(){
        $oid = gp('oid');
        if(!$oid){
            json_output('','维修单号不能为空',false);
        }
        $productList = $this->common_model->selectCustom('maintain_product',array('maintain_id'=>$oid));
        //订单下所有产品
        $pids = array();
        foreach ($productList as $key=>$rs) {
            $pids[] = $rs['product_id'];
        }
        if(!$pids){
            json_output('','当前订单没有产品',false);
        }
        //产品下所有物料
        $materialArr = $this->common_model->selectCustom('maintain_accessory','','pid desc',array('pid'=>$pids));
        json_output($materialArr,'返回成功!',true);

    }

}